package com.sun.dailyprj.androidx.data_binding.cases.db.entity;

import com.sun.dailyprj.androidx.data_binding.cases.db.model.Comment;

import java.util.Date;

import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.Index;
import androidx.room.PrimaryKey;

/*
 * =====================================================================================
 * Summary:
 *
 * File: CommentEntity.java
 * Author: Yanpeng.Sun
 * Create: 2019/5/14 11:29
 * =====================================================================================
 */
@Entity(tableName = "comment",
    foreignKeys = {
        @ForeignKey(entity = ProductEntity.class,
        parentColumns = "id",
        childColumns = "poductId",
        onDelete = ForeignKey.CASCADE)
    },
    indices = {@Index(value = "productId")})
public class CommentEntity implements Comment{
    @PrimaryKey(autoGenerate = true)//主键，true表示自增长
    private int id;
    private int productId;
    private String text;
    private Date postedAt;

    public CommentEntity() {
    }

    @Ignore
    public CommentEntity(int id, int productId, String text, Date postedAt) {
        this.id = id;
        this.productId = productId;
        this.postedAt = postedAt;
        this.text = text;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getProductId() {
        return productId;
    }

    public void setProductId(int productId) {
        this.productId = productId;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Date getPostedAt() {
        return postedAt;
    }

    public void setPostedAt(Date postedAt) {
        this.postedAt = postedAt;
    }
}
